#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define mes(x) memset(x,0,sizeof(x))
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)

ll f[32][1010];
vector <int> v[32],w[32];
int n,m,l,sv[32];

int main(){
	while(scanf("%d %d",&n,&m) == 2 && (~n) && (~m)){
		l = 0; mes(sv),mes(f);
		for(int i = 0;i < 32;i++) v[i].clear(),w[i].clear();
		for(int i = 1;i <= n;i++){
			int x,y;scanf("%d %d",&x,&y);
			int j = 0;
			while(!(x&1)) j++,x>>=1;
			v[j].push_back(x);w[j].push_back(y);
			l = max(l,j);
			sv[j] += x;
		}
		for(int i = 0;i <= l;i++)
			for(int j = 0;j < v[i].size();j++){
				int xv = v[i][j],xw = w[i][j];
				for(int k = sv[i];k >= xv;k--){
					f[i][k] = max(f[i][k],f[i][k-xv] + xw);
				}
			}
		l = 0;
		while(m >> l) l++;
		for(int i = 1;i < l;i++){
			sv[i] += (sv[i-1]+1)/2;
			for(int k = sv[i];k >= 0;k--)
				for(int d = 0;d <= k;d++)
					f[i][k] = max(f[i][k],f[i][k-d]+f[i-1][min(sv[i-1],(d<<1)|(m>>(i-1)&1))]);
		}
		printf("%lld\n",f[l-1][1]);
	}
	return 0;
}
